package veterinaria.servlet.cliente;

import java.io.IOException;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import veterinaria.excepcion.DAOExcepcion;
import veterinaria.modelo.Cliente;
import veterinaria.negocio.GestionAdministrarClientes;	

/**
 * Servlet implementation class ClienteInsertarServlet
 */
@WebServlet("/ClienteInsertarServlet")
public class ClienteInsertarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ClienteInsertarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
	//	int idCliente = Integer.parseInt(request.getParameter("idCliente"));
		
		String dsNombre = request.getParameter("nombre");
		String dsApellido = request.getParameter("apellido");
		String dsCorreo = request.getParameter("correo");
		String dsDireccion = request.getParameter("direccion");
		String nuTeleFijo = request.getParameter("fonocasa");
		String nuTeleMovil = request.getParameter("celular");
		boolean flCliente = Boolean.parseBoolean(request.getParameter("condicion"));
		String nuRuc = request.getParameter("ruc");
		String dsImagenCliente = request.getParameter("imagen");
		String dsNotasCliente = request.getParameter("notas");
		String stActivo = request.getParameter("estado");
		
		
	//	GestionAdministrarClientes negocio = new GestionAdministrarClientes();
		try {
			GestionAdministrarClientes negocio = new GestionAdministrarClientes();
			int i= negocio.obtenerId2();
			int idCliente = i+1;
			negocio.insertar(idCliente, dsNombre, dsApellido, dsCorreo, dsDireccion, nuTeleFijo, nuTeleMovil, flCliente, nuRuc, dsImagenCliente, dsNotasCliente, "1");
			response.sendRedirect(request.getContextPath()	+ "/confInsCliente.jsp?id="+idCliente+"&nombre="+dsNombre+"&apellido="+dsApellido);
		} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error.jsp");
			rd.forward(request, response);
		}

	}

}
